#include <string.h>
#include "qe_vars.h"
#include "qe_func.h"



struct q_func func_table[256];
int q_func_count = 0;

int q_registerfunc(const char* const name, const char* const arglist, struct q_variable (*ptr)(struct q_variable* var_list))
{
	if(!name || !strlen(name) || !strlen(name) > MAX_FUN_LEN - 1 || !arglist || strlen(arglist) > MAX_ARG_LEN - 1 || !ptr)
		return -1;
	
	//strncpy(func_table[q_func_count].name, name, MAX_FUN_LEN);
	strncpy(func_table[q_func_count].arglist, arglist, MAX_ARG_LEN);
	func_table[q_func_count].ptr = ptr;
	++q_func_count;
	return 0;
}

int q_runfunc(const char* const name, struct q_variable* return_value, struct q_variable* arglist)
{
	int i;
	if(!name || !strlen(name) || !strlen(name) > MAX_FUN_LEN - 1)
		return -1;
	for(i = 0; i < q_func_count; ++i)
	{
		//if(!strncmp(name, func_table[i].name, MAX_FUN_LEN))
		{
			*return_value = func_table[i].ptr(arglist);
			return 0;
		}
	}
	return -1;
}

